package com.ruoyi.tb.lmt.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.core.domain.PageQuery;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import com.ruoyi.tb.lmt.domain.bo.McgsFpf109ezBo;
import com.ruoyi.tb.lmt.domain.vo.McgsFpf109ezVo;
import com.ruoyi.tb.lmt.domain.McgsFpf109ez;
import com.ruoyi.tb.lmt.mapper.McgsFpf109ezMapper;
import com.ruoyi.tb.lmt.service.IMcgsFpf109ezService;

import java.util.List;
import java.util.Map;
import java.util.Collection;

/**
 * 制动阀试验台_分配阀109E组_MCGSService业务层处理
 *
 * @author ruoyi
 * @date 2023-12-13
 */
@RequiredArgsConstructor
@Service
public class McgsFpf109ezServiceImpl implements IMcgsFpf109ezService {

    private final McgsFpf109ezMapper baseMapper;

    /**
     * 查询制动阀试验台_分配阀109E组_MCGS
     */
    @Override
    public McgsFpf109ezVo queryById(Long id){
        return baseMapper.selectVoById(id);
    }

    /**
     * 查询制动阀试验台_分配阀109E组_MCGS列表
     */
    @Override
    public TableDataInfo<McgsFpf109ezVo> queryPageList(McgsFpf109ezBo bo, PageQuery pageQuery) {
        LambdaQueryWrapper<McgsFpf109ez> lqw = buildQueryWrapper(bo);
        Page<McgsFpf109ezVo> result = baseMapper.selectVoPage(pageQuery.build(), lqw);
        return TableDataInfo.build(result);
    }

    /**
     * 查询制动阀试验台_分配阀109E组_MCGS列表
     */
    @Override
    public List<McgsFpf109ezVo> queryList(McgsFpf109ezBo bo) {
        LambdaQueryWrapper<McgsFpf109ez> lqw = buildQueryWrapper(bo);
        return baseMapper.selectVoList(lqw);
    }

    private LambdaQueryWrapper<McgsFpf109ez> buildQueryWrapper(McgsFpf109ezBo bo) {
        Map<String, Object> params = bo.getParams();
        LambdaQueryWrapper<McgsFpf109ez> lqw = Wrappers.lambdaQuery();
        lqw.eq(bo.getId() != null, McgsFpf109ez::getId, bo.getId());
        lqw.eq(StringUtils.isNotBlank(bo.getDjNo()), McgsFpf109ez::getDjNo, bo.getDjNo());
        lqw.eq(StringUtils.isNotBlank(bo.getMcgsTime()), McgsFpf109ez::getMcgsTime, bo.getMcgsTime());
        lqw.eq(StringUtils.isNotBlank(bo.getMcgsCzz()), McgsFpf109ez::getMcgsCzz, bo.getMcgsCzz());
        lqw.eq(StringUtils.isNotBlank(bo.getMcgsTimeMs()), McgsFpf109ez::getMcgsTimeMs, bo.getMcgsTimeMs());
        lqw.eq(StringUtils.isNotBlank(bo.getMcgsJxbh()), McgsFpf109ez::getMcgsJxbh, bo.getMcgsJxbh());
        lqw.eq(StringUtils.isNotBlank(bo.getMcgsFh()), McgsFpf109ez::getMcgsFh, bo.getMcgsFh());
        lqw.eq(StringUtils.isNotBlank(bo.getMcgsSch()), McgsFpf109ez::getMcgsSch, bo.getMcgsSch());
        lqw.eq(StringUtils.isNotBlank(bo.getMcgsFpf1()), McgsFpf109ez::getMcgsFpf1, bo.getMcgsFpf1());
        lqw.eq(StringUtils.isNotBlank(bo.getMcgsFpf2()), McgsFpf109ez::getMcgsFpf2, bo.getMcgsFpf2());
        lqw.eq(StringUtils.isNotBlank(bo.getMcgsFpf3()), McgsFpf109ez::getMcgsFpf3, bo.getMcgsFpf3());
        lqw.eq(StringUtils.isNotBlank(bo.getMcgsFpf4()), McgsFpf109ez::getMcgsFpf4, bo.getMcgsFpf4());
        lqw.eq(StringUtils.isNotBlank(bo.getMcgsFpf5()), McgsFpf109ez::getMcgsFpf5, bo.getMcgsFpf5());
        lqw.eq(StringUtils.isNotBlank(bo.getMcgsFpf6()), McgsFpf109ez::getMcgsFpf6, bo.getMcgsFpf6());
        lqw.eq(StringUtils.isNotBlank(bo.getMcgsFpf7()), McgsFpf109ez::getMcgsFpf7, bo.getMcgsFpf7());
        lqw.eq(StringUtils.isNotBlank(bo.getMcgsFpf8()), McgsFpf109ez::getMcgsFpf8, bo.getMcgsFpf8());
        lqw.eq(StringUtils.isNotBlank(bo.getMcgsFpf9()), McgsFpf109ez::getMcgsFpf9, bo.getMcgsFpf9());
        lqw.eq(StringUtils.isNotBlank(bo.getMcgsFpf10()), McgsFpf109ez::getMcgsFpf10, bo.getMcgsFpf10());
        lqw.eq(StringUtils.isNotBlank(bo.getMcgsFpf11()), McgsFpf109ez::getMcgsFpf11, bo.getMcgsFpf11());
        lqw.eq(StringUtils.isNotBlank(bo.getMcgsFpf12()), McgsFpf109ez::getMcgsFpf12, bo.getMcgsFpf12());
        lqw.eq(StringUtils.isNotBlank(bo.getMcgsFpf13()), McgsFpf109ez::getMcgsFpf13, bo.getMcgsFpf13());
        lqw.eq(StringUtils.isNotBlank(bo.getMcgsFpf14()), McgsFpf109ez::getMcgsFpf14, bo.getMcgsFpf14());
        lqw.eq(StringUtils.isNotBlank(bo.getMcgsFpf15()), McgsFpf109ez::getMcgsFpf15, bo.getMcgsFpf15());
        lqw.eq(StringUtils.isNotBlank(bo.getMcgsFpf16()), McgsFpf109ez::getMcgsFpf16, bo.getMcgsFpf16());
        lqw.eq(StringUtils.isNotBlank(bo.getMcgsFpf17()), McgsFpf109ez::getMcgsFpf17, bo.getMcgsFpf17());
        lqw.eq(StringUtils.isNotBlank(bo.getMcgsFpf18()), McgsFpf109ez::getMcgsFpf18, bo.getMcgsFpf18());
        lqw.eq(StringUtils.isNotBlank(bo.getMcgsFpf19()), McgsFpf109ez::getMcgsFpf19, bo.getMcgsFpf19());
        lqw.eq(StringUtils.isNotBlank(bo.getMcgsFpf20()), McgsFpf109ez::getMcgsFpf20, bo.getMcgsFpf20());
        lqw.eq(StringUtils.isNotBlank(bo.getMcgsFpf21()), McgsFpf109ez::getMcgsFpf21, bo.getMcgsFpf21());
        lqw.eq(StringUtils.isNotBlank(bo.getMcgsBy1()), McgsFpf109ez::getMcgsBy1, bo.getMcgsBy1());
        lqw.eq(StringUtils.isNotBlank(bo.getMcgsZsch()), McgsFpf109ez::getMcgsZsch, bo.getMcgsZsch());
        lqw.eq(StringUtils.isNotBlank(bo.getMcgsKzc()), McgsFpf109ez::getMcgsKzc, bo.getMcgsKzc());
        lqw.eq(StringUtils.isNotBlank(bo.getDelFlag()), McgsFpf109ez::getDelFlag, bo.getDelFlag());
        lqw.eq(StringUtils.isNotBlank(bo.getCreateBy()), McgsFpf109ez::getCreateBy, bo.getCreateBy());
        lqw.eq(bo.getCreateTime() != null, McgsFpf109ez::getCreateTime, bo.getCreateTime());
        lqw.eq(StringUtils.isNotBlank(bo.getUpdateBy()), McgsFpf109ez::getUpdateBy, bo.getUpdateBy());
        lqw.eq(bo.getUpdateTime() != null, McgsFpf109ez::getUpdateTime, bo.getUpdateTime());
        return lqw;
    }
    /**
     * 新增制动阀试验台_分配阀109E组_MCGS
     */
    @Override
    public Boolean insertByBo(McgsFpf109ezBo bo) {
        McgsFpf109ez add = BeanUtil.toBean(bo, McgsFpf109ez.class);
        add.setDelFlag("0");
        validEntityBeforeSave(add);
        boolean flag = baseMapper.insert(add) > 0;
        if (flag) {
            bo.setId(add.getId());
        }
        return flag;
    }

    /**
     * 修改制动阀试验台_分配阀109E组_MCGS
     */
    @Override
    public Boolean updateByBo(McgsFpf109ezBo bo) {
        McgsFpf109ez update = BeanUtil.toBean(bo, McgsFpf109ez.class);
        validEntityBeforeSave(update);
        return baseMapper.updateById(update) > 0;
    }

    /**
     * 保存前的数据校验
     */
    private void validEntityBeforeSave(McgsFpf109ez entity){
        //TODO 做一些数据校验,如唯一约束
    }

    /**
     * 批量删除制动阀试验台_分配阀109E组_MCGS
     */
    @Override
    public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
        if(isValid){
            //TODO 做一些业务上的校验,判断是否需要校验
        }
        return baseMapper.deleteBatchIds(ids) > 0;
    }

    @Override
    public String getMaxMcgsTime(){
        return baseMapper.getMaxMcgsTime();
    }
}
